package com.cskaoyan.demo6.service;


import com.cskaoyan.demo6.bean.model.*;
import com.cskaoyan.demo6.bean.vo.HomeIndexVo;
import com.cskaoyan.demo6.mapper.MarketAdMapper;
import com.cskaoyan.demo6.mapper.MarketBrandMapper;
import com.cskaoyan.demo6.mapper.MarketCategoryMapper;
import com.cskaoyan.demo6.mapper.MarketSystemMapper;
import com.github.pagehelper.PageHelper;
import jdk.jfr.Category;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description：
 * @Author：BLUEBLANK
 * @Date：2024/4/20 21:02
 */

@Service("homeService")
public class HomeServiceImpl implements HomeService {


    @Autowired
    SystemService systemService;
    @Autowired
    BrandService brandService;
    @Autowired
    AdService adService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    CouponService couponService;
    @Autowired
    GoodsService goodsService;
    @Autowired
    TopicService topicService;


    @Override
    public HomeIndexVo index() {
        HomeIndexVo homeIndexVo = new HomeIndexVo();

        // 查询配置
        Map<String, String> map = systemService.querySystemConfig();


        // 查询banner  广告，没有限制
        List<HomeIndexVo.BannerDTO> banner = adService.query();
        homeIndexVo.setBanner(banner);

        // 查询品牌
        Integer brandLimit = Integer.parseInt(map.get("market_wx_index_brand"));
        List<HomeIndexVo.BrandListDTO> brand = brandService.select(0, brandLimit);
        homeIndexVo.setBrandList(brand);

        // channel  在表 market_category 中查询
        // L1的全部
        List<MarketCategory> l1Categories = categoryService.selectL1();
        List<HomeIndexVo.ChannelDTO> channel = new ArrayList<>();
        l1Categories.forEach(marketCategory -> {
            HomeIndexVo.ChannelDTO channelDTO = new HomeIndexVo.ChannelDTO();
            BeanUtils.copyProperties(marketCategory, channelDTO);
            channel.add(channelDTO);
        });
        homeIndexVo.setChannel(channel);

        // couponlist
        // 查询优惠券
        // 由于功能不完善，不能做是否登录处理，直接显示所有优惠券中的三条
        Integer couponLimit = 3;
        List<HomeIndexVo.CouponListDTO> couponList = couponService.select(0, couponLimit);
        homeIndexVo.setCouponList(couponList);

        // floorGoodsList 5  里面有goodsList 2
        Integer catlogListLimit = Integer.parseInt(map.get("market_wx_catlog_list"));
        Integer catlogGoodsLimit = Integer.parseInt(map.get("market_wx_catlog_goods"));
        List<HomeIndexVo.FloorGoodsListDTO> floorGoodsList = categoryService.selectList(0, catlogListLimit, catlogGoodsLimit);
        homeIndexVo.setFloorGoodsList(floorGoodsList);


        // hotGoodsList
        Integer hotLimit = Integer.parseInt(map.get("market_wx_index_hot"));
        List<HomeIndexVo.HotGoodsListDTO> hotGoodsListList = goodsService.queryByHot(0, hotLimit);
        homeIndexVo.setHotGoodsList(hotGoodsListList);

        // newGoodsList
        Integer newLimit = Integer.parseInt(map.get("market_wx_index_new"));
        List<HomeIndexVo.NewGoodsListDTO> newGoodsListList = goodsService.queryByNew(0, newLimit);
        homeIndexVo.setNewGoodsList(newGoodsListList);

        // topicList
        Integer topicLimit = Integer.parseInt(map.get("market_wx_index_topic"));
        List<HomeIndexVo.TopicListDTO> topicListList = topicService.queryList(0, topicLimit);
        homeIndexVo.setTopicList(topicListList);


        return homeIndexVo;
    }
}
